#ifndef ADC_CONVERT_H
#define ADC_CONVERT_H

#include "delay.h"

#define ADC_VREF_TYPE 0x00

// ADC initialization
// ADC Clock frequency: 1000,000 kHz
void adc_init()
{
  ADMUX=ADC_VREF_TYPE & 0xff;
  ADCSR=0x84;
}
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
  ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
  // Delay needed for the stabilization of the ADC input voltage
  delay_us(10);
  // Start the AD conversion
  ADCSR|=0x40;
  // Wait for the AD conversion to complete
  while ((ADCSR & 0x10)==0);
  ADCSR|=0x10;
  return ADC;
}

#endif